Skip to content

feat: migrate bb-prover from direct binary execution to bb.js API#21564

Open
charlielye wants to merge 1 commit intonextfrom
cl/bb_js_api_migrate
Open

feat: migrate bb-prover from direct binary execution to bb.js API#21564
charlielye wants to merge 1 commit intonextfrom
cl/bb_js_api_migrate

Conversation

@charlielye
Copy link
Copy Markdown
Contributor

@charlielye charlielye commented Mar 14, 2026

Summary

Migrates all bb-prover server-side proving and verification from spawning bb/bb-avm binaries via child_process.spawn() to using the bb.js TypeScript API (Barretenberg class via NativeUnixSocket backend). This eliminates temporary file I/O (writing/reading bytecode, witnesses, proofs, VKs to disk) and stdout-based result parsing. A fresh bb process is still spawned per proof to maintain parallelism, but communication happens via Unix socket instead of files.

What was migrated

Operation Before After
UltraHonk proving bb prove via spawn api.circuitProve() via bb.js
UltraHonk verification bb verify via spawn api.circuitVerify() via bb.js
Chonk (IVC) verification bb verify --scheme chonk via spawn + temp files api.chonkVerify() via bb.js
AVM proving bb-avm avm_prove via spawn + temp files api.avmProve() via bb.js
AVM verification bb-avm avm_verify via spawn + temp files api.avmVerify() via bb.js
AVM circuit check bb-avm avm_check_circuit via spawn + temp files api.avmCheckCircuit() via bb.js
Gate counting bb gates via spawn api.circuitStats() / api.chonkStats() via bb.js
Solidity contract gen bb contract via spawn api.circuitWriteSolidityVerifier() via bb.js

Key changes

  • New BBJsInstance / BBJsProverFactory (bb_js_backend.ts): Adapter layer wrapping the Barretenberg class with typed methods for all proof operations
  • New DebugBBJsInstance (bb_js_debug.ts): Debug wrapper that writes inputs/outputs to disk and logs equivalent CLI commands (see debug section below)
  • C++ AVM msgpack commands (bbapi_avm.hpp/cpp): Three new bbapi command structs (AvmProve, AvmVerify, AvmCheckCircuit) with in-memory function implementations in vm2/api_avm.cpp and stub implementations in vm2_stub/api_avm.cpp
  • Chonk proof splitting (splitChonkProofToStructured): Converts flat Fr[] proof arrays to structured ChonkProof format expected by chonkVerify, using sub-proof sizes inlined from C++ static_assert values
  • Removed ~415 lines from execute.ts (6 dead functions)

Debug workflow with BB_DEBUG_OUTPUT_DIR

Set the BB_DEBUG_OUTPUT_DIR environment variable to enable file-based debugging. When set, DebugBBJsInstance wraps all bb.js calls and:

  1. Writes all inputs (bytecode, witness, VK, proof, etc.) to numbered subdirectories under the debug dir
  2. Writes a command.sh script with the equivalent bb CLI command that can be re-run manually
  3. Writes outputs (proof files, verification results) after each operation

Example:

BB_DEBUG_OUTPUT_DIR=/tmp/bb-debug yarn workspace @aztec/prover-client test
# Then inspect /tmp/bb-debug/0001_prove_MyCircuit/, /tmp/bb-debug/0002_verify_MyCircuit/, etc.

Each subdirectory contains the input files and a command.sh that reproduces the operation using the bb CLI binary, useful for isolating failures outside of the TypeScript stack.

Test plan

  • CI green on all checks
  • Chonk integration tests pass
  • AVM proving tests pass
  • E2E block building tests pass

🤖 Generated with Claude Code

Copy link
Copy Markdown
Contributor

Hey Charlie, this looks nice, just one comment for the AVM. We regularly use the following flow for all kinds of debugging, testing, benchmarking and iterating: we run some test (e.g., the avm bulk test). This test writes the avm inputs file and outputs the exact bb-avm command that you'd need to run. After that, we can just use that command (and that file) and operate 100% on the CLI/C++ side. We can then easily change the passed environment variables, concurrency, etc. IIUC, these changes would break that because the files wouldn't be written?

@charlielye
Copy link
Copy Markdown
Contributor Author

charlielye commented Mar 14, 2026

Hey Charlie, this looks nice, just one comment for the AVM. We regularly use the following flow for all kinds of debugging, testing, benchmarking and iterating.

This should now be covered by setting a BB_DEBUG_OUTPUT_DIR before running.

@charlielye charlielye force-pushed the cl/bb_js_api_migrate branch 2 times, most recently from 25f6490 to 613e654 Compare March 23, 2026 02:53
@charlielye charlielye force-pushed the cl/bb_js_api_migrate branch from 613e654 to 970f34c Compare March 23, 2026 04:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants